<?php
class advertiseModel extends Model{
	private $tbl = 'advertise';
	private $rule = array();

	public function __construct(){
		parent::__construct($this->tbl);
	}

	public function get_advertises($where="", $order="", $limit=""){
		return $this->where($where)->order($order)->limit($limit)->get(); 
	}

	public function get_advertise($where){
		return $this->where($where)->get_one();	
	}

	public function count_advertises($where=""){
		return $this->where($where)->count();
	}

	public function add($data){
		//if( !$this->valid($data, $this->rule) ) return false;
		return $this->value($data)->insert();
	}

	public function del($id){
		if( is_int($id) && $id>0 ){
			return $this->where("id=$id")->delete();
		}	
	}

	public function batch_del($arrIds){
		if( !is_array($arrIds) ) return false;
		return $this->where("id IN (".implode(',',$arrIds).")")->delete();
	}

	public function edit($id, $data){
		if( !is_int($id) || !$this->valid($data, $this->rule) ) return false;
		return $this->where("id=$id")->value($data)->update();
	}
}
